home *** CD-ROM | disk | FTP | other *** search
/ Pro One: Resistances / ProOne: Electronics: Resistances.iso / cdbackup / progfile.sfs / LAUNCHER.PAS < prev    next >
Pascal/Delphi Source File  |  1998-03-23  |  4KB  |  131 lines

  1. program Launcher;
  2.  
  3. uses
  4.   WinTypes, WinProcs, IniFiles, SysUtils;
  5.  
  6. {$R *.RES}
  7.  
  8. {$DEFINE NewEngineLayout}
  9.   { Define the above if this is based on the new engine layout }
  10.  
  11.  
  12. Const
  13.   cProductIdFileName = 'ID921416.ID_';  { !!! MUST match PRODUCT_ID_FILENAME in CUSTOM.RUL !!! }
  14.   cProgramKeyName    = '92141-6';       { !!! MUST match APP_UPC_CODE in CUSTOM.RUL !!! }
  15.   cSectionName       = 'Sofsource';     { !!! MUST match PROGRAM_FOLDER_NAME in CUSTOM.RUL !!! }
  16.   {$IFDEF NewEngineLayout}
  17.    BinarySetName = 'SET001\';
  18.   {$ENDIF}
  19.  
  20.   cPermanentSetupLog = 'SOF_LOG_.INI';  { Don't change this value }
  21.  
  22. const
  23.   DosDelimSet : set of Char = ['\', ':', #0];
  24.  
  25.  
  26. Var
  27.   IniLog : TIniFile;
  28.   FileToFind,
  29.   RecordedDestination : String;
  30.  
  31.  
  32.  
  33. Function AddBackSlash( Const DirName : String ) : String;
  34.   { Add a default backslash to a directory name }
  35. Begin
  36.  
  37.   If DirName[ Length(DirName) ] in DosDelimSet Then
  38.     AddBackSlash := DirName
  39.   ELSE
  40.     AddBackSlash := DirName + '\';
  41.  
  42. End; { Function AddBackSlash }
  43.  
  44.  
  45.  
  46. Function JustPathname( Const PathName : String ) : String;
  47.   { Return just the drive:directory portion of a pathname }
  48. Var
  49.   I : Word;
  50. Begin
  51.  
  52.   I := Succ( Word( Length(PathName) ) );
  53.   Repeat
  54.     Dec(I);
  55.   Until (PathName[I] in DosDelimSet) or (I = 0);
  56.  
  57.   If I = 0 Then { Had no drive or directory name }
  58.     JustPathname[0] := #0              
  59.   ELSE
  60.     If I = 1 Then { Either the root directory of default drive or invalid pathname }
  61.       JustPathname := PathName[1]      
  62.     ELSE
  63.       If (PathName[I] = '\') Then
  64.       Begin
  65.         If PathName[Pred(I)] = ':' Then { Root directory of a drive, leave trailing backslash }
  66.           JustPathname := Copy(PathName, 1, I)   
  67.         ELSE { Subdirectory, remove the trailing backslash }
  68.           JustPathname := Copy(PathName, 1, Pred(I)); 
  69.       End
  70.       ELSE { Either the default directory of a drive or invalid pathname }
  71.         JustPathname := Copy(PathName, 1, I);
  72.  
  73. End; { Function JustPathName }
  74.  
  75.  
  76.  
  77. Procedure LaunchSetup;
  78. Var
  79.   FileToExecute  : String;
  80.   pFileToExecute : Array[0..254] of Char;
  81. Begin
  82.  
  83.   FileToExecute := AddBackSlash( JustPathName( ParamStr(0)) );
  84.  
  85.   ChDir( FileToExecute );
  86.                    
  87.   FileToExecute := AddBackSlash( FileToExecute) + 'SETUP.EXE AUTOPLAY';
  88.                   
  89.   StrPCopy( pFileToExecute, FileToExecute );
  90.  
  91.   If WinExec( pFileToExecute, sw_ShowNormal ) < 32 Then
  92.   Begin
  93.     MessageBeep( mb_IconHand );
  94.     MessageBox( 0, 'Unable to launch "SETUP.EXE"', 'Error', 0 );
  95.   End;        
  96.  
  97. End; { Procedure LaunchSetup }
  98.  
  99.  
  100. {$IFDEF NewEngineLayout}
  101.  Function GetFileToFind( RecordedDest : String ) : String;
  102.  Begin
  103.    { Remove the last backslash }
  104.    If Copy( RecordedDest, Length(RecordedDest), 1 ) = '\' Then
  105.      Delete( RecordedDest, Length(RecordedDest), 1 );
  106.    Result := JustPathName( RecordedDest );
  107.    Result := AddBackSlash( Result ) + BinarySetName;
  108.  End; { GetFileToFind }
  109. {$ENDIF}
  110.  
  111. begin
  112.  
  113.   IniLog := TIniFile.Create( cPermanentSetupLog );
  114.   RecordedDestination := IniLog.ReadString( cSectionName, cProgramKeyName, '' );
  115.   IniLog.Free;
  116.  
  117.   If RecordedDestination = '' Then
  118.     LaunchSetup
  119.   ELSE
  120.   Begin
  121.     {$IFDEF NewEngineLayout}
  122.      FileToFind := GetFileToFind( RecordedDestination ) + cProductIDFileName;
  123.     {$ELSE}
  124.      FileToFind := AddBackSlash( RecordedDestination ) + cProductIDFileName;
  125.     {$ENDIF}
  126.     If NOT FileExists( FileToFind ) Then
  127.       LaunchSetup;
  128.   End;
  129.  
  130. end.
  131.